package com.example.bottomnavigationproject.fragmentexample;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.bottomnavigationproject.R;

public class FragmentActivityExample extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_transaction_test);
        //// 步骤1：获取FragmentManager
        FragmentManager fragmentManager = getSupportFragmentManager();
        //// 步骤2：获取FragmentTransaction
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        // 步骤3：创建需要添加的Fragment ：ExampleFragment
        ExampleFragment exampleFragment = new ExampleFragment();

        // // 步骤4：动态添加fragment
        //        // 即将创建的fragment添加到Activity布局文件中定义的占位符中（FrameLayout）
        transaction.add(R.id.add_fragment_container,exampleFragment);

        //提交
        transaction.commit();



    }
}
